package com.restaurant.springboot.service.impl;


import com.restaurant.springboot.entity.DishesEntity;
import com.restaurant.springboot.entity.DishesSeriesEntity;
import com.restaurant.springboot.repositories.DishesRepository;
import com.restaurant.springboot.repositories.DishesSeriesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Transient;
import java.util.List;

@Service
public class DishesSeriesServiceImpl implements com.restaurant.springboot.service.DishesSeriesService {

    @Autowired
    private DishesRepository dishesRepository;

    @Autowired
    private DishesSeriesRepository dishesSeriesRepository;

    @Override
    @Transient
    public void deleteDishesSeries(DishesSeriesEntity dishesSeries){
        System.out.println(dishesSeries.getId());
        dishesRepository.deleteAllDishesByDishesSeriesId(dishesSeries.getId());
        dishesSeriesRepository.delete(dishesSeries);
    }

    @Override
    public List<DishesEntity> getDishesByDishesSeriesId(int dishesSeriesId){
        return dishesRepository.findAllByDishesSeriesId(dishesSeriesId);
    }

    @Override
    @Transient
    public boolean saveDishesSeries(DishesSeriesEntity dishesSeries){
        if(dishesSeriesRepository.save(dishesSeries)!=null){
            return true;
        }
        return false;
    }

    @Override
    public List<DishesSeriesEntity> getAllDishesService(){
        return dishesSeriesRepository.findAll();
    }

    @Override
    public DishesSeriesEntity getDishesSeriesById(int dishesSeriesId){
        return dishesSeriesRepository.findById(dishesSeriesId).get();
    }

}
